home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWSTRTOO_H
- #define FWSTRTOO_H
- //========================================================================================
- //
- // File: FWStrToo.h
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- //========================================================================================
- // CLASS FW_CStringTool
- //
- // A tool for string operations. StringTools are used for operations that don't fit
- // well as methods of strings. The principle reason for placing an operation in a
- // tool instead of a string is when the operation may have multiple algorithm
- // implementations. We make this distinction because it is undesirable to force
- // a user to subclass one or more string classes just to use a different set of
- // tool algorithms.
- //
- // Note that "StringTool" is only one kind of "string tool". Other string tools
- // include translation tools, format tools, etc. This StringTool class is intended
- // for "pure string" manipulation, e.g. searching and comparing.
- //
- // The FW_CStringTool class is an abstract base class.
- //========================================================================================
-
- enum FW_StringCompareResult
- {
- kStringOneLess = -1, kStringsEqual = 0, kStringOneGreater = 1
- } ;
-
- // Note: The following enumeration should be class scoped, but Borland croaks later
- // on if this is class scoped.
-
- enum FW_FindDirection { FW_kForwards, FW_kBackwards };
-
- class FW_CStringTool : public _FW_CAutoDestructObject
- {
- public:
-
- virtual ~FW_CStringTool();
- FW_CStringTool(FW_Boolean caseSensitive=TRUE);
-
- FW_Boolean SetCaseSensitivity(FW_Boolean caseSensitive);
- // Sets the sensitivity, returns prior sensitivity
-
- FW_StringCompareResult CompareStrings(FW_CTextReader &reader1,
- FW_CTextReader &reader2);
-
- FW_StringCompareResult CompareStrings(const FW_CString &string1,
- const FW_CString &string2);
-
- FW_Boolean FindSubString(FW_CTextReader &reader,
- const FW_CString &subString,
- FW_CharacterPosition &foundPosition);
-
- FW_Boolean FindSubString(const FW_CString &string,
- const FW_CString &subString,
- FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition=0);
-
- FW_Boolean FindCharacter(FW_CTextReader &reader,
- FW_Char character,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards);
-
- FW_Boolean FindCharacter(const FW_CString &string,
- FW_Char character,
- FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition=0,
- FW_FindDirection direction=FW_kForwards);
-
- FW_Boolean IsWhiteSpace(FW_Char character);
-
- FW_Boolean IsWhiteSpace(FW_CTextReader &reader);
-
- FW_Boolean FindWhiteSpace(FW_CTextReader &reader,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards);
-
- FW_Boolean FindWhiteSpace(const FW_CString &string,
- FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition=0,
- FW_FindDirection direction=FW_kForwards);
-
- FW_Boolean FindNonWhiteSpace(FW_CTextReader &reader,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards);
-
- FW_Boolean FindNonWhiteSpace(const FW_CString &string,
- FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition=0,
- FW_FindDirection direction=FW_kForwards);
-
- FW_Boolean Substitute(FW_CString &string,
- const FW_CString &searchString,
- const FW_CString &substitutionString);
-
- void ToUpper(FW_CTextReader &input, FW_CTextWriter &output);
-
- void ToUpper(FW_CString &string);
-
- void ToLower(FW_CTextReader &input, FW_CTextWriter &output);
-
- void ToLower(FW_CString &string);
-
- // ----- Static functions for accessing default and current string tools.
-
- static FW_CStringTool* GetCurrentStringTool();
- // Return a pointer to the current string tool.
-
- static FW_CStringTool* SetCurrentStringTool(FW_CStringTool* tool);
- // Make tool the current string tool.
- // Returns the prior string tool.
-
- protected:
-
- virtual FW_StringCompareResult DoCompareStrings(FW_CTextReader &reader1,
- FW_CTextReader &reader2) = 0;
-
- virtual FW_Boolean DoMatchPrefixString(FW_CTextReader &target,
- FW_CTextReader &prefix) = 0;
-
- virtual FW_Boolean DoFindSubString(FW_CTextReader &searchStringReader,
- FW_CTextReader &subStringReader,
- FW_CharacterPosition &foundPosition) = 0;
-
- virtual FW_Boolean DoFindCharacter(FW_CTextReader &reader,
- FW_Char character,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards) = 0;
-
- virtual FW_Boolean DoFindWhiteSpace(FW_CTextReader &reader,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards) = 0;
-
- virtual FW_Boolean DoFindNonWhiteSpace(FW_CTextReader &reader,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards) = 0;
-
- virtual FW_Boolean DoIsWhiteSpace(FW_Char character) = 0;
-
- virtual void DoConvertToUpper(FW_Char *chars, FW_CharacterCount length) = 0;
-
- virtual void DoConvertToLower(FW_Char *chars, FW_CharacterCount length) = 0;
-
- FW_Boolean fCaseSensitive;
-
- private:
-
- static FW_CStringTool*& GetTool();
-
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CStringTool::CompareStrings
- //----------------------------------------------------------------------------------------
-
- inline FW_StringCompareResult FW_CStringTool::CompareStrings(
- FW_CTextReader &reader1,
- FW_CTextReader &reader2)
- {
- return DoCompareStrings(reader1, reader2);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringTool::FindCharacter
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CStringTool::FindCharacter(FW_CTextReader& reader,
- FW_Char character,
- FW_CharacterPosition& foundPosition,
- FW_FindDirection direction)
- {
- return DoFindCharacter(reader, character, foundPosition, direction);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CStringTool::IsWhiteSpace
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CStringTool::IsWhiteSpace(FW_Char character)
- {
- return DoIsWhiteSpace(character);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringTool::FindWhiteSpace
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CStringTool::FindWhiteSpace(
- FW_CTextReader &reader,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction)
- {
- return DoFindWhiteSpace(reader, foundPosition, direction);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringTool::FindNonWhiteSpace
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CStringTool::FindNonWhiteSpace(
- FW_CTextReader &reader,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction)
- {
- return DoFindNonWhiteSpace(reader, foundPosition, direction);
- }
-
- //========================================================================================
- // CLASS FW_CMinimalStringTool
- //
- // A minimalist, braindead string tool. Operations are done without any knowledge
- // of language, locale, character set, case sensitivity, etc. This tool is provided
- // for quick and dirty use where lack of such knowledge is not considered a problem.
- // Real applications will need to use more sophisticated string tools, provided in
- // other, higher level components.
- //========================================================================================
-
- class FW_CMinimalStringTool : public FW_CStringTool
- {
- public:
-
- virtual ~FW_CMinimalStringTool();
- FW_CMinimalStringTool(FW_Boolean caseSensitive=TRUE);
-
- protected:
-
- virtual FW_StringCompareResult DoCompareStrings(FW_CTextReader &reader1,
- FW_CTextReader &reader2);
-
- virtual FW_Boolean DoMatchPrefixString(FW_CTextReader &target,
- FW_CTextReader &prefix);
-
- virtual FW_Boolean DoFindSubString(FW_CTextReader &searchStringReader,
- FW_CTextReader &subStringReader,
- FW_CharacterPosition &foundPosition);
-
- virtual FW_Boolean DoFindCharacter(FW_CTextReader &reader,
- FW_Char character,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards);
-
- virtual FW_Boolean DoFindWhiteSpace(FW_CTextReader &reader,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards);
-
- virtual FW_Boolean DoFindNonWhiteSpace(FW_CTextReader &reader,
- FW_CharacterPosition &foundPosition,
- FW_FindDirection direction=FW_kForwards);
-
- virtual FW_Boolean DoIsWhiteSpace(FW_Char character);
-
- virtual void DoConvertToUpper(FW_Char *chars, FW_CharacterCount length);
-
- virtual void DoConvertToLower(FW_Char *chars, FW_CharacterCount length);
-
- };
-
- #endif
-